<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>客户信息管理</title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/jquery-easyui-1.8.6/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/jquery-easyui-1.8.6/themes/icon.css">
    <script type="text/javascript" src="${pageContext.request.contextPath}/jquery-easyui-1.8.6/jquery.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/jquery-easyui-1.8.6/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/jquery-easyui-1.8.6/locale/easyui-lang-zh_CN.js"></script>
</head>
<body>

<%--客户信息展示数据网格--%>
<table id="dg" title="客户信息查询" class="easyui-datagrid" pagination="true" rownumbers="true" url="${pageContext.request.contextPath}/customer/list.do" fit="true" toolbar="#dg-tb">
    <thead data-options="frozen:true">
    <tr>
        <th field="cb" checkbox="true" align="center"></th>
        <th field="id" width="50" align="center" hidden="true">编号</th>
        <th field="khno" width="150" align="center">客户编号</th>
        <th field="name" width="200" align="center">客户名称</th>
        <th field="cusManager" width="100" align="center">客户经理</th>
        <th field="level" width="100" align="center">客户等级</th>
        <th field="phone" width="100" align="center">联系电话</th>
    </tr>
    </thead>
    <thead>
    <tr>
        <th field="area" width="80" align="center">客户地区</th>
        <th field="myd" width="80" align="center">客户满意度</th>
        <th field="xyd" width="80" align="center">客户信用度</th>
        <th field="address" width="200" align="center">客户地址</th>
        <th field="postCode" width="100" align="center">邮政编码</th>
        <th field="fax" width="100" align="center">传真</th>
        <th field="webSite" width="100" align="center">网址</th>
        <th field="yyzzzch" width="100" align="center">营业执照注册号</th>
        <th field="fr" width="100" align="center">法人</th>
        <th field="zczj" width="100" align="center">注册资金(万元)</th>
        <th field="nyye" width="100" align="center">年营业额(万元)</th>
        <th field="khyh" width="100" align="center">开户银行</th>
        <th field="khzh" width="100" align="center">开户帐号</th>
        <th field="dsdjh" width="100" align="center">地税登记号</th>
        <th field="gsdjh" width="100" align="center">国税登记号</th>
    </tr>
    </thead>
</table>
<div id="dg-tb">
    <div>
        <a href="javascript:openCustomerAddDialog()" class="easyui-linkbutton" iconCls="icon-add" plain="true">创建</a>
        <a href="javascript:openCustomerModifyDialog()" class="easyui-linkbutton" iconCls="icon-edit" plain="true">修改</a>
        <a href="javascript:deleteCustomer()" class="easyui-linkbutton" iconCls="icon-remove" plain="true">删除</a>
        <a href="javascript:openCustomerLinkMan()" class="easyui-linkbutton" iconCls="icon-lxr" plain="true">联系人管理</a>
        <a href="javascript:openCustomerLinkNote()" class="easyui-linkbutton" iconCls="icon-lxjl" plain="true">联系记录管理</a>
        <a href="javascript:openCustomerOrder()" class="easyui-linkbutton" iconCls="icon-lsdd" plain="true">历史订单查看</a>
    </div>
    <div>
        &nbsp;客户编号：&nbsp;<input class="easyui-textbox" id="s_khno" name="s_khno" data-options="width:100"/>
        &nbsp;客户名称：&nbsp;<input class="easyui-textbox" id="s_name" name="s_name" data-options="width:100"/>
        <a href="javascript:searchCustomer()" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a>
    </div>
</div>

<%--客户信息添加/修改对话框--%>
<div id="dlg" class="easyui-dialog" data-options="closed:true,buttons:'#dlg-btns',onClose:closeCustomerDialog" style="width:850px;height:550px;padding: 10px 20px">
    <form id="fm" method="post">
        <table cellspacing="8px">
            <tr>
                <td>客户名称：</td>
                <td><input class="easyui-textbox" id="name" name="name" required="true"/>&nbsp;<font color="red">*</font></td>
                <td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
                <td>地区</td>
                <td><input class="easyui-combobox" id="area" name="area" data-options="panelHeight:'auto',editable:false,valueField:'dataDicValue',textField:'dataDicValue',url:'${pageContext.request.contextPath}/dataDic/dataDicValueComboList.do?dataDicName=地区'" required="true" style="width: 163px">&nbsp;<font color="red">*</font></td>
            </tr>
            <tr>
                <td>客户经理：</td>
                <td><input class="easyui-combobox" id="cusManager" name="cusManager" data-options="panelHeight:'auto',editable:false,valueField:'trueName',textField:'trueName',url:'${pageContext.request.contextPath}/user/customerManagerComboList.do'" required="true" style="width: 163px">&nbsp;<font color="red">*</font></td>
                <td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
                <td>客户等级：</td>
                <td><input class="easyui-combobox" id="level" name="level" data-options="panelHeight:'auto',editable:false,valueField:'dataDicValue',textField:'dataDicValue',url:'${pageContext.request.contextPath}/dataDic/dataDicValueComboList.do?dataDicName=客户等级'" required="true" style="width: 163px"/>&nbsp;<font color="red">*</font></td>
            </tr>
            <tr>
                <td>客户满意度：</td>
                <td><input class="easyui-combobox" id="myd" name="myd" data-options="panelHeight:'auto',editable:false,valueField:'dataDicValue',textField:'dataDicValue',url:'${pageContext.request.contextPath}/dataDic/dataDicValueComboList.do?dataDicName=客户满意度'" required="true" style="width: 163px"/>&nbsp;<font color="red">*</font></td>
                <td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
                <td>客户信用度</td>
                <td><input class="easyui-combobox" id="xyd" name="xyd" data-options="panelHeight:'auto',editable:false,valueField:'dataDicValue',textField:'dataDicValue',url:'${pageContext.request.contextPath}/dataDic/dataDicValueComboList.do?dataDicName=客户信用度'" required="true" style="width: 163px"/>&nbsp;<font color="red">*</font></td>
            </tr>
            <tr>
                <td>邮政编码：</td>
                <td><input class="easyui-textbox" id="postCode" name="postCode" required="true"/>&nbsp;<font color="red">*</font></td>
                <td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
                <td>联系电话：</td>
                <td><input class="easyui-textbox" id="phone" name="phone" required="true"/>&nbsp;<font color="red">*</font></td>
            </tr>
            <tr>
                <td>传真：</td>
                <td><input class="easyui-textbox" id="fax" name="fax" required="true"/>&nbsp;<font color="red">*</font></td>
                <td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
                <td>网址：</td>
                <td><input class="easyui-textbox" id="webSite" name="webSite" required="true"/>&nbsp;<font color="red">*</font></td>
            </tr>
            <tr>
                <td>客户地址：</td>
                <td colspan="4">
                    <input class="easyui-textbox" id="address" name="address" multiline="true" required="true" style="width: 420px;height:44px"/>&nbsp;<font color="red">*</font>
                </td>
            </tr>
            <tr>
                <td>营业执照注册号：</td>
                <td><input class="easyui-textbox" id="yyzzzch" name="yyzzzch"/></td>
                <td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
                <td>法人：</td>
                <td><input class="easyui-textbox" id="fr" name="fr" required="true"/>&nbsp;<font color="red">*</font></td>
            </tr>
            <tr>
                <td>注册资金(万元)：</td>
                <td><input class="easyui-textbox" id="zczj" name="zczj"/></td>
                <td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
                <td>年营业额(万元)：</td>
                <td><input class="easyui-textbox" id="nyye" name="nyye" required="true"/>&nbsp;<font color="red">*</font></td>
            </tr>
            <tr>
                <td>开户银行：</td>
                <td><input class="easyui-textbox" id="khyh" name="khyh" required="true"/>&nbsp;<font color="red">*</font></td>
                <td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
                <td>开户帐号：</td>
                <td><input class="easyui-textbox" id="khzh" name="khzh" required="true"/>&nbsp;<font color="red">*</font></td>
            </tr>
            <tr>
                <td>地税登记号：</td>
                <td><input class="easyui-textbox" id="dsdjh" name="dsdjh"/></td>
                <td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
                <td>国税登记号：</td>
                <td><input class="easyui-textbox" id="gsdjh" name="gsdjh"/></td>
            </tr>
        </table>
    </form>
</div>
<div id="dlg-btns">
    <a href="javascript:saveCustomer()" class="easyui-linkbutton" iconCls="icon-ok">保存</a>
    <a href="javascript:closeCustomerDialog()" class="easyui-linkbutton" iconCls="icon-cancel">关闭</a>
</div>
</body>
</html>

<script>

    $(function () {
        $('#s_khno,#s_name').each(function (index, element) {
            $(this).textbox('textbox').bind('keydown', function (e) {
                if (e.keyCode == 13) {   // 当按下回车键时接受输入的值。
                    searchCustomer();
                }
            });
        });
    });

    var url;

    function searchCustomer() {
        $("#dg").datagrid('load', {
            "khno": $("#s_khno").textbox("getValue"),
            "name": $("#s_name").textbox("getValue")
        });
    }

    function openCustomerAddDialog() {
        $("#dlg").dialog("setTitle", "添加客户信息").dialog("open");
        url = "${pageContext.request.contextPath}/customer/save.do";
    }

    function openCustomerModifyDialog() {
        var selectedRows = $("#dg").datagrid("getSelections");
        if (selectedRows.length != 1) {
            $.messager.alert("系统提示", "请选择一条要编辑的数据！");
            return;
        }
        var selectedRow = selectedRows[0];
        $("#dlg").dialog("open").dialog("setTitle", "修改客户信息");
        $("#fm").form("load", selectedRow);
        url = "${pageContext.request.contextPath}/customer/save.do?id=" + selectedRow.id;
    }

    function saveCustomer() {
        $("#fm").form("submit", {
            url: url,
            onSubmit: function () {
                return $(this).form("validate");
            },
            success: function (result) {
                var result = eval('(' + result + ')');
                if (result.success) {
                    $.messager.alert("系统提示", "保存成功！");
                    resetValue();
                    $("#dlg").dialog("close");
                    $("#dg").datagrid("reload");
                } else {
                    $.messager.alert("系统提示", "保存失败！");
                    return;
                }
            }
        });
    }

    function deleteCustomer() {
        var selectedRows = $("#dg").datagrid("getSelections");
        if (selectedRows.length == 0) {
            $.messager.alert("系统提示", "请选择要删除的数据！");
            return;
        }
        var idsArr = [];
        for (var i = 0; i < selectedRows.length; i++) {
            idsArr.push(selectedRows[i].id);
        }
        var idsStr = idsArr.join(",");
        $.messager.confirm("系统提示", "您确定要删除这<span style='color: red'>" + selectedRows.length + "</span>条记录吗？", function (r) {
            if (r) {
                $.post("${pageContext.request.contextPath}/customer/delete.do", {ids: idsStr}, function (result) {
                    if (result.success) {
                        $.messager.alert("系统提示", "已成功删除数据！");
                        $("#dg").datagrid("reload");
                    } else {
                        $.messager.alert("系统提示", "删除数据失败，请联系系统管理员！");
                    }
                }, "json");
            }
        });
    }

    function closeCustomerDialog() {
        var dlgOptions = $("#dlg").dialog("options");
        if (dlgOptions.closed != true) {
            $("#dlg").dialog("close");
        }
        $("#fm").form("reset");
        $("#dg").datagrid("reload");
        $(".easyui-combobox").each(function (index, element) {
            $(this).combobox("reload");
        });
    }

    function openCustomerLinkMan() {
        var selectedRows = $("#dg").datagrid("getSelections");
        if (selectedRows.length != 1) {
            $.messager.alert("系统提示", "请选择一条要管理的数据！");
            return;
        }
        window.parent.openTab('联系人管理', 'linkManManage.jsp?cusId=' + selectedRows[0].id, 'icon-lxr');
    }

    function openCustomerLinkNote() {
        var selectedRows = $("#dg").datagrid("getSelections");
        if (selectedRows.length != 1) {
            $.messager.alert("系统提示", "请选择一条要管理的数据！");
            return;
        }
        window.parent.openTab('联系记录管理', 'linkNoteManage.jsp?cusId=' + selectedRows[0].id, 'icon-lxjl');
    }

    function openCustomerOrder() {
        var selectedRows = $("#dg").datagrid("getSelections");
        if (selectedRows.length != 1) {
            $.messager.alert("系统提示", "请选择一条要管理的数据！");
            return;
        }
        window.parent.openTab('客户历史订单查询', 'orderManage.jsp?cusId=' + selectedRows[0].id, 'icon-lsdd');
    }
</script>